package SerovaGS;
import robocode.*;
import java.awt.Color;
import java.util.Random;

/**
 * Anku - a robot by (your name here)
 */
public class Anku extends AdvancedRobot
{
	
	private Random rnd = new Random();
	private double moveDist = 100000;
	/**
	 * run: Anku's default behavior
	 */
	public void run() {
		setColors(Color.red,Color.blue,Color.green);
		while(true) {
			setTurnRadarRight(360000);
			setAhead(moveDist);
			setTurnRight(getRandomAngle());
			waitFor(new TurnCompleteCondition(this));
			
			setAhead(getRandomDist());
			waitFor(new MoveCompleteCondition(this));
		}
	}

	/**
	 * onScannedRobot: What to do when you see another robot
	 */
	public void onScannedRobot(ScannedRobotEvent e) {
		double angleToTarget = getHeading() + e.getBearing();
		
		turnGunRight(angleToTarget-getGunHeading());
		fire(3);
		
		turnRadarRight(angleToTarget-getRadarHeading());
		scan();
	}
	
	public void onHitWall(HitWallEvent e) {
		reverse();
		turnLeft(getHeading()%90);
	}

	/**
	 * onHitByBullet: What to do when you're hit by a bullet
	 */
	public void onHitByBullet(HitByBulletEvent e) {
		turnLeft(90 - e.getBearing());
	}
	
	public int getRandomAngle() {
		return rnd.nextInt()%200;
	}
	
	public int getRandomDist() {
		return rnd.nextInt()%300;
	}
	
	public void reverse() {
		moveDist *= -1;
	}
	
}
